import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { UploadImageComponent } from '../upload-image/upload-image.component';
import { ImgPage } from '../upload-image/img.page';
import { ImgSlidePage } from '../slides-imgage/img-slide.page';
import { AppGlobalService } from '../../shared/service/app-global.service';
import { HttpService } from 'src/app/shared/service/http.service';
@Component({
    selector: 'app-extend-picture',
    templateUrl: './extend-picture.component.html',
    styleUrls: ['./extend-picture.component.scss'],
})
export class ExtendPictureComponent implements OnInit {
    @Output() updateIdentity: EventEmitter<any> = new EventEmitter();
    img: any = [];   // 图片显示
    currentItem: any = {};
    @Input() tagData: any;
    params: any = {}; // 需要传的参数
    // 当前页数，默认1
    pageNo = 1;
    sessionId: any;
    constructor(private modalCtrl: ModalController, private appGlobalService: AppGlobalService, private http: HttpService) { }

    ngOnInit() {
        console.log(this.tagData)
        /* this.openImageModal(); */
        /* this.tagData={
          "type":"tag",
          "style":"appInfoListTag",
          "name":"appInfoListTag",
          "linearLayout":"body",
          "data":{
              "isMargin":false,
              "data":[
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"https://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_8a260375c15f1fec46bb699ea32ce273.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"http://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_2c4de361c51f9e2914b09ec56dcffd0d.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"https://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_8a260375c15f1fec46bb699ea32ce273.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"https://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_8a260375c15f1fec46bb699ea32ce273.jpg",
                      "name":"图片描述"
                  },
                  {
                      "path":"https://zeno-img.oss-cn-shenzhen.aliyuncs.com/file_8a260375c15f1fec46bb699ea32ce273.jpg",
                      "name":"图片描述"
                  }
              ],
              "submit":{
                  "content":{
                      "opportunity_id":"5ebbbdc0defd3e00019e1ce8",
                      "pageNo":1
                  },
                  "id":"ac9438fb-c5ba-4869-811c-21dfefea3191"
              }
          },
          "pageSize":10,
          "pageNo":1,
          "pageTotal":468
      } */
        this.img = this.tagData.data.data;
    }
    // 打开图片展示框，滑动展示
    async openImg(pos) {
        console.log(' message-----> 273 upload pos[' + (pos) + '] ');
        const that = this;
        const modal = await this.modalCtrl.create({
            component: ImgPage,
            componentProps: { value: JSON.stringify(this.img), index: pos, isShowDel: false }
        });
        modal.onDidDismiss().then(function (data) {
            that.img = data.data;
        });
        return await modal.present();
    }
    // 打开图片展示框，滑动展示2
    async openImage_url(index, images) {
        console.log(index + 'index' + images)
        const value = { img: images, index: index + 1 };
        console.log(value)
        const modal = await this.modalCtrl.create({
            component: ImgSlidePage,
            componentProps: { value: JSON.stringify(value) }
        });
        return await modal.present();
    }
    /* 上划获取翻页 */
    loadMoreData(event) {
        console.log(event);
        this.params = this.tagData.data.submit;
        // // 请求下一个页面
        this.pageNo = this.pageNo + 1;
        // // 参数
        this.params.content.pageNo = this.pageNo;
        this.params.sessionId = localStorage.getItem('sessionId');
        console.log(this.params);
        // 请求获取新数据
        this.http.post('application/submit', this.params, res => {
            console.log(res)
            console.log('cheng============================')
            // 请求数据成功
            if (res.success) {
                const resList = res.data.data;
                console.log(resList)
                // 追加返回数据
                if (resList && resList.length > 0) {
                    // 追加数据
                    resList.map(v => {
                        /*   v.payTimes = this.tranNumber(v.payTimes, 1); */
                        this.tagData.data.data.push(v);
                    });
                } else {
                    event.target.disabled = true;
                    // 没有数据了
                    // this.appGlobalService.showToast('没有数据了...', 1000, 'middle');
                }
            } else {
                // 请求失败，更新当前页数
                this.pageNo = this.pageNo - 1;
                // 请求数据失败
                this.appGlobalService.showToast(res.message, 2000, 'middle');
            }
            event.target.complete();
        }, err => {
            // 请求失败，更新当前页数
            this.pageNo = this.pageNo - 1;
            // 请求数据失败
            this.appGlobalService.showToast(err.message, 2000, 'middle');
            event.target.complete();

        });
    }
}
